var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "materialCode",
			name : "物料编码"
		}, {
			colkey : "name",
			name : "名称"
		}, {
			colkey : "specifications",
			name : "规格"
		}, {
			colkey : "unit",
			name : "单位"
		}, {
			colkey : "initialNumber",
			name : "初期结存数量"
		}, {
			colkey : "initialPrice",
			name : "平均单价"
		}, {
			colkey : "initialMoney",
			name : "初期结存金额"
		}, {
			colkey : "currentInNumber",
			name : "本期收入数量"
		}, {
			colkey : "currentInPrice",
			name : "平均单价"
		}, {
			colkey : "currentInMoney",
			name : "本期收入金额"
		}, {
			colkey : "currentOutNumber",
			name : "本期发出数量"
		}, {
			colkey : "currentOutPrice",
			name : "平均单价"
		}, {
			colkey : "currentOutMoney",
			name : "本期发出金额"
		}, {
			colkey : "lastNumber",
			name : "末期结存数量"
		}, {
			colkey : "lastPrice",
			name : "平均单价"
		}, {
			colkey : "lastMoney",
			name : "末期结存金额"
		}, {
			colkey : "checkNumber",
			name : "盘点"
		}, {
			colkey : "profitAndLoss",
			name : "盈亏"
		}],
		jsonUrl : rootPath + '/parts/SesaleStock_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#editFun").click("click", function() {
		editAccount();
	});	
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
});
function editAccount(jq) {
	var cbox = grid.getSelectedCheckbox();
	var trdata = $("#mytable input:checked").parent().parent().children();
	console.log($("#mytable input:checked").parent().parent().children());
	var cdata=[ 
		"materialCode"
	, 
		"name"
	, 
		"specifications"
	, 
		"unit"
	, 
		"initialNumber"
	, 
		"initialPrice"
	, 
		"initialMoney"
	, 
		"currentInNumber"
	, 
		"currentInPrice"
	, 
		"currentInMoney"
	, 
		"currentOutNumber"
	, 
		"currentOutPrice"
	, 
		"currentOutMoney"
	, 
		"lastNumber"
	, 
		"lastPrice"
	, 
		"lastMoney"
	, 
		"checkNumber"
	, 
		"profitAndLoss"
	];
	var newdata = "";
	var kbj = "";
	$.each(trdata, function(i,item){      
		if(i>1){
			if(i==trdata.length-2){
				kbj = $(item).html();
			}
			if(i==trdata.length-1){
				newdata += $(item).html();
			}else{
				newdata += $(item).html()+",";
			}
			
		}
		
	});
	if(kbj!="可编辑"){
		layer.msg("只能编辑可编辑的盘点");
		return;
	}
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "编辑盘点",
		type : 2,
		dataType:"json",
		area : [ "800px", "100%" ],
		content : rootPath + '/parts/parts_sell_edit.shtml?id=' + newdata
	});
}


